
#include "data/UserInfo.h"

#include <Array.hpp>
#include <ByteArrayIOStream.h>
#include <System.h>
#include <array>
#include <boost/json.hpp>
#include <cstring>
#include <iostream>
#include <openssl/OpenSSL.h>
#include <packet/request/Request.h>
#include <fstream>
#include <memory>

const std::string smtp_password = "tpbyeposwokeejbg";

using namespace sys;

void test_Array() {
    ByteArray data;
    data.resize(10);

    // data.fill('H');
    data.resize(20);
    strcpy(data.data(), "Hello world!哈哈");

    for (auto&& i : data) {
        std::cout << i;
    }
    std::cout << std::endl;

    data.clear();

    for (auto&& i : data) {
        std::cout << i;
    }
    std::cout << std::endl;
}

void test_array_shared() {
    System::out << "start" << std::endl;
    auto arr = std::make_shared<ByteArray>();
    arr->resize(123);
    arr->resize(1024);

    ByteArray a = std::move(*arr);
    System::out << "end" << std::endl;
}

void test_std__array() {
}

void testArrayStream() {
    ByteArray arr;
    arr.resize(20);
    ByteArrayIOStream stream(arr);
    stream << 123;
    stream << 3234;
}
void testUserInfo() {
    data::UserInfo user{"hansi", "100001"};
    user.name   = "hansi";
    user.userId = "100001";

    boost::json::value jv      = boost::json::value_from(user);
    auto               jsonStr = boost::json::serialize(jv);

    std::cout << jsonStr << std::endl;

    data::UserInfo user1 = boost::json::value_to<data::UserInfo>(jv);

    std::cout << "userId:" << user1.userId << std::endl;
    std::cout << "name:" << user1.name << std::endl;
}

void test_request() {
    using namespace packet;
    using namespace packet::request;
    using namespace boost;
    Request req;
    req.method = request::Login;
    req.body   = {
        {"userId", "100001"},
        {"userName", "hansi"},

    };
    auto jv = boost::json::value_from(req);
    auto js = json::serialize(jv);
    System::out << json::serialize(jv) << std::endl;
    Request r = json::value_to<Request>(jv);
    System::out << "method:" << r.method << std::endl;
    // System::out << "method:" << r.method<<std::endl;
}

void testJson() {
    using namespace boost;

    std::string str = "haha 你好aaa";
    std::string s1;

    System::in >> s1;
    json::value jv = {
        {"text", str},
        {"s1", s1},
    };

    System::out << json::serialize(jv) << std::endl;
}

void testOpenSSL() {
    std::string id = "100sdfasdfasda001";
    System::out << "Hash256 :" << openssl::Hash256(id) << std::endl;
    System::out << "MD5     :" << openssl::MD5(id) << std::endl;
    System::out << "Hash1   :" << openssl::Hash1(id) << std::endl;
}

int main(int argc, char const* argv[]) {
    // testArrayStream();
    // testOpenSSL();
    // try {
    //     // auto hash = openssl::GetFileHash("D:/SGA/Videos/LoginVideo.mp4", openssl::Algorithm::MD5);
    //     auto hash = openssl::Hash(std::ifstream("D:/SGA/Videos/LoginVideo.mp4", std::ios::binary), openssl::Algorithm::MD5);
    //     System::out << hash << std::endl;
    // }
    // catch (const std::exception& e) {
    //     System::err << e.what() << std::endl;
    // }

    std::vector<char> var;
    var.resize(1024 * 32 );
    System::out << var.size();

    return 0;
}
